from typing import List

from exceptions.unzip_excepotion import CompressionError
from interface.unzip_interfaces import CompressionTool


class WinRarCompressor(CompressionTool):

    def build_command(self) -> List[str]:
        """构建WinRAR压缩命令

        Returns:
            List[str]: 构建好的命令列表

        Raises:
            CompressionError: 当缺少必要参数时抛出
        """
        if not self._config.output_path:
            raise CompressionError("未指定输出路径")
        if not self._config.input_path:
            raise CompressionError("未添加压缩文件")

        command = ["winrar", "a", "-y", "-ep1"]

        if self._config.password:
            command.append("-p" + self._config.password)

        if self._config.volume:
            command.append("-v" + self.config.volume)

        command.append(f"{str(self._config.output_path)}")
        command.append(self._config.input_path)

        self.log.info(f"构建命令：{' '.join(command)}")
        return command


if __name__ == '__main__':
    compressor = WinRarCompressor()
    compressor.set_input_path(r"E:\myproject\python\extract-script\log\unzip.7z").set_password("123456") \
        .set_output_path("D:\\test.zip").set_compression_type("zip").set_volume(10000)
    compressor.build_command()
